package com.shopmall.controller.system;


import com.shopmall.common.ResponseData;
import com.shopmall.system.dao.MenuMapper;
import com.shopmall.system.entity.Menu;
import com.shopmall.system.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys")
public class MenuController extends ResponseData {
    @Autowired
    MenuMapper menuMapper;
    @Autowired
    IMenuService menuService;

    @GetMapping("/menu")
    public ResponseData test(){
        List<Menu> allMenus = menuMapper.getAllMenus();
        return success(allMenus);
    }

    @PostMapping("/menuList")
    public ResponseData menuList(@RequestBody Menu menu){
        List<Menu> allMenus = menuService.pageList(menu);
        return success(allMenus);
    }

    @PostMapping("/addOrUpdateMenu")
    public ResponseData addOrUpdateMenu(@RequestBody Menu menu){
        int num = menuService.addOrUpdateMenu(menu);
        if(num>0){
            return success("操作成功");
        }
        return failed("操作失败");
    }

    @GetMapping("/deleteMenu/{id}")
    public ResponseData deleteMenu(@PathVariable Integer id){
        int num = menuService.deleteMenuById(id);
        if(num>0){
            return success("操作成功");
        }
        return failed("操作失败");
    }

    @GetMapping("getRuleMenu")
    public ResponseData getRuleMenu(){
        return null;
    }

}
